﻿using Application.AppService.HFAppService;
using Application.AppService.SGAppService;
using Application.AppService.SGDAppService;
using Application.Service;
using AutoMapper;
using Domain;
using Domain.Entity;
using Hangfire;
using Microsoft.AspNetCore.Mvc;
using System;

namespace UI.Controllers.Salary_management_薪酬发放管理_
{
    public class PayrollCheckController : Controller
    {
        private readonly IHFAppService hfAppServoice;
        private readonly ISGDAppService sGDAppService;
        private readonly ISGAppService sGAppService;
        private readonly ISalaryService salaryService;

        private readonly IMapper mapper;

        public PayrollCheckController(IHFAppService hfAppServoice, IMapper mapper, ISGDAppService sGDAppService, ISGAppService sGAppService, ISalaryService salaryService)
        {
            this.hfAppServoice = hfAppServoice;
            this.sGDAppService = sGDAppService;
            this.sGAppService = sGAppService;
            this.salaryService = salaryService;
            this.mapper = mapper;
        }
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Index1()
        {
            return View();
        }
        [HttpPost("SGFenYe")]
        public IActionResult SGFenYe(int page, int pageSize)
        {
            SGFenYe sgfenye = sGAppService.SelectSGFenYeAsync(page, pageSize);
            return Json(sgfenye);
        }

        [HttpPost("GetAllSgdSalaryGrantId")]
        public async Task<IActionResult> GetAllSgdSalaryGrantId(string SalaryGrantId)
        {
            List<SGD> sGDs = await sGDAppService.GetAllSgdSalaryGrantIdAsync(SalaryGrantId);
            return Json(sGDs);
        }

        [HttpPost("GetSalaryGrantIdAsync")]
        public async Task<IActionResult> GetSalaryGrantIdAsync(string HumanId)
        {
            string bh = await hfAppServoice.GetSalaryGrantIdAsync(HumanId);
            return Json(bh);
        }

        [HttpPost("RemoveSGAsync")]
        public async Task<IActionResult> RemoveSGAsync(string SalaryGrantId, double totalCostS, string Checker)
        {
            bool zhi= await sGAppService.RemoveSGAsync(SalaryGrantId, totalCostS, Checker);
            return Json(zhi);
        }

        [HttpPost("RemoveSGDAsync")]
        public async Task<IActionResult> RemoveSGDAsync(int GrdId, double BounsSum, double SaleSum, double DeductSum, double SalaryPaidSum)
        {
            bool zhi = await sGDAppService.RemoveSGDAsync(GrdId, BounsSum, SaleSum, DeductSum, SalaryPaidSum);
            return Json(zhi);
        }
        [HttpPost("Salary")]
        public  IActionResult Salary(string humanId, int zt )
        {
            // 安排下一个任务在一个月后执行  
            var nextExecutionTime = DateTime.UtcNow.AddMonths(1);
            BackgroundJob.Schedule(() => salaryService.Salary(humanId, zt), nextExecutionTime);
            return Ok("薪酬任务已执行，并安排下一个任务在一个月后执行");
        }
    }
}
